package com.xujiakai.car.maintain.domain.entity;

import com.xujiakai.car.maintain.application.service.impl.SystemManageService;
import com.xujiakai.car.maintain.domain.dto.AccountDTO;
import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Permission {
    private Integer id;

    private String pername;

    private String authcategory;

    private String perurl;

    private String perflag;

    @Resource
    private DaoFactory daoFactory;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPername() {
        return pername;
    }

    public void setPername(String pername) {
        this.pername = pername == null ? null : pername.trim();
    }

    public String getAuthcategory() {
        return authcategory;
    }

    public void setAuthcategory(String authcategory) {
        this.authcategory = authcategory == null ? null : authcategory.trim();
    }

    public String getPerurl() {
        return perurl;
    }

    public void setPerurl(String perurl) {
        this.perurl = perurl == null ? null : perurl.trim();
    }

    public String getPerflag() {
        return perflag;
    }

    public void setPerflag(String perflag) {
        this.perflag = perflag == null ? null : perflag.trim();
    }

    public List<com.xujiakai.car.maintain.domain.dto.PermissionDTO> queryPermission() {
        return daoFactory.getPermissionMapper().selectAllPermission();
    }

    public boolean modifyPermission(com.xujiakai.car.maintain.domain.dto.PermissionDTO permission) {
        boolean flag = false;
        if (permission != null) {
            com.xujiakai.car.maintain.domain.dto.PermissionDTO perm = daoFactory.getPermissionMapper().selectByPrimaryKey(permission.getId());
            perm.setPerflag(permission.getPerflag());
            flag = daoFactory.getPermissionMapper().updateByPrimaryKeySelective(perm) > 0;
        }
        return flag;
    }

    public boolean modifyPass(String password, String accountnumber) {
        boolean flag = false;
        try {
            AccountDTO account = daoFactory.getAccontMapper().selectByAccountNum(accountnumber);
            account.setPasswords(password);
            flag = daoFactory.getAccontMapper().updateByPrimaryKeySelective(account) > 0;
        } catch (Exception e) {
            SystemManageService.logger.info("成功修改密码!");
        }
        return flag;
    }


}